package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/minimum-number-of-vertices-to-reach-all-nodes/">1557. 可以到达所有点的最少点数目</a>
 */
public class Solution1557 extends BaseSolution {

    public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
        int[] start = new int[n];
        for (List<Integer> item : edges) {
            int a = item.get(0);
            int b = item.get(1);
            if (start[a] != 1) {
                start[a] = -1;
            }
            start[b] = 1;
        }
        List<Integer> rst = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if (start[i] == -1) {
                rst.add(i);
            }
        }
        return rst;
    }

    public static void main(String[] args) {
        Solution1557 solution = new Solution1557();
    }
}